package com.onlyphoto.onlymall.mvp.view.binder

import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView

import com.onlyphoto.onlymall.R
import com.bumptech.glide.Glide
import com.onlyphoto.onlymall.bean.response.OrderDetailsBean
import com.onlyphoto.onlymall.utils.StringUtil

import me.drakeet.multitype.ItemViewBinder

/**
 * Created by gaochujia on 2019-08-26.
 */
class OrderDetailsGoodsBinder : ItemViewBinder<OrderDetailsBean.GoodsInfo, OrderDetailsGoodsBinder.ViewHolder>() {

    override fun onCreateViewHolder(inflater: LayoutInflater, parent: ViewGroup): ViewHolder {
        val root = inflater.inflate(R.layout.item_order, parent, false)
        return ViewHolder(root)
    }

    override fun onBindViewHolder(viewHolder: ViewHolder, bean: OrderDetailsBean.GoodsInfo) {
        viewHolder.update(bean)

    }

    class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {


        var img: ImageView? = null
        var title: TextView? = null
        var style: TextView? = null
        var price: TextView? = null
        var count: TextView? = null

        init {
            img = itemView.findViewById(R.id.img_order)
            title = itemView.findViewById(R.id.title)
            style = itemView.findViewById(R.id.style)
            price = itemView.findViewById(R.id.price)
            count = itemView.findViewById(R.id.count)
        }

        @SuppressLint("SetTextI18n")
        fun update(bean: OrderDetailsBean.GoodsInfo) {
            Glide.with(img!!.context).load(bean.front_img).placeholder(R.mipmap.img_default).into(img!!)
            title?.text = bean.title
            price?.text = "¥ " + bean.price_now.toString()
            count?.text = "x${bean.buy_num}"
            if (StringUtil.isBlank(bean.style)) {
                style?.text = bean.color + ";" +bean.size
            } else {
                style?.text = bean.style
            }
        }

    }
}
